<?php
include('calculator.class.php');
class BlackScholes extends Calculator {

    protected function cnd($x) {
		//constants
		$Pi = 3.142;
		$val1 = 0.319381530;
		$val2 = -0.356563782;
		$val3 = 1.781477937;
		$val4 = -1.821255978;
		$val5 = 1.330274429;
		
		$L = abs($x);
		$k = 1 / ( 1 + 0.2316419 * $L);
		$p = 1 - 1 /  pow(2 * $Pi, 0.5) * exp( -pow($L, 2) / 2 ) * ($val1 * $k + $val2 * pow($k, 2) + $val3 * pow($k, 3) + $val4 * pow($k, 4) + $val5 * pow($k, 5) );

		if ($x >= 0) { 
			return $p;
		} else {
			return 1-$p;
		}
	}
}
?>